﻿using System.Data;
using System.Data.SqlClient;
using TeachingManageSystem.DAL;
using TeachingManageSystem.Entity;

namespace TeachingManageSystem.BLL
{
    public class BookTypeBll : DBHelper
    {
        #region 执行存储过程GetAllBookType 获取所有的BookType值
        public static DataSet GetBookType()
        {
            return ProGetData("GetAllBookType", null);
        }
        #endregion

        #region BookType插入新值
        public static int InsertBookType(BookType bookType)
        {
            var sqlParameters = new SqlParameter[2];
            sqlParameters[0] = MakeInParam("@name", SqlDbType.NVarChar, 50, bookType.Name);
            sqlParameters[1] = MakeInParam("@remark", SqlDbType.NVarChar, 100, bookType.Remark);
            return ProManageData("InsertBookType", sqlParameters);
        }
        #endregion

        #region 根据BookType的ID删除数据
        public static int DeleteBookTypeByID(int  bookTypeid)
        {
            var sqlParamters = new SqlParameter[1];
            sqlParamters[0] = MakeInParam("@id", SqlDbType.Int, 20, bookTypeid);
            return ProManageData("DeleteBookTypeByID", sqlParamters);
        }
        #endregion

        #region  根据类别的ID更新数据
        public static int UpdateBookTypeByID(BookType bookType)
        {
            var sqlParameters = new SqlParameter[3];
            sqlParameters[0] = MakeInParam("@id", SqlDbType.Int, 20, bookType.ID);
            sqlParameters[1] = MakeInParam("@name", SqlDbType.NVarChar, 50, bookType.Name);
            sqlParameters[2] = MakeInParam("@remark", SqlDbType.NVarChar, 100, bookType.Remark);
            return ProManageData("UpdateBookTypeByID",sqlParameters);
        }
        #endregion

        #region 检测教材的类别名是否存在
        public static string  CheckBookTypeName(BookType bookType)
        {
            var sqlParamters = new SqlParameter[1];
            sqlParamters[0] = MakeInParam("@name", SqlDbType.NVarChar, 50, bookType.Name);
            var name = ProGetData("ChenkBookTypeName", sqlParamters).Tables[0];
            if(name.Rows.Count==0)
            {
                return "0";
            }
            return name.Rows[0][0] as string;
        }
        #endregion
    }
}
